#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
#define rep(i, a, b) for (int i = (a); i <= (b); i++)
#define per(i, a, b) for (int i = (a); i >= (b); i--)
#define endl '\n'
const int N = 2e5 + 5;

int n, m;
struct Node {
  int tag;              // -1, 0, 1
  int len;              // 区间长度
  int sum;              // 1 的个数
  int left, right, mx;  // 0 的信息
} tr[N << 2];
#define tag(p) tr[p].tag
#define len(p) tr[p].len
#define sum(p) tr[p].sum
#define left(p) tr[p].left
#define right(p) tr[p].right
#define mx(p) tr[p].mx

void merge(Node a, Node b, Node& c) {
  c.len = a.len + b.len;
  c.sum = a.sum + b.sum;
  c.mx = max({a.mx, b.mx, a.right + b.left});
  c.left = !a.sum ? a.len + b.left : a.left;
  c.right = !b.sum ? b.len + a.right : b.right;
}
void pushup(int p) { merge(tr[p << 1], tr[p << 1 | 1], tr[p]); }
void addtag(int d, int p) {
  tag(p) = d;
  sum(p) = len(p) * d;
  left(p) = right(p) = mx(p) = len(p) * (1 - d);
}
void pushdown(int p) {
  if (tag(p) != -1) {
    addtag(tag(p), p << 1);
    addtag(tag(p), p << 1 | 1);
    tag(p) = -1;
  }
}
void build(int p, int l, int r) {
  tag(p) = -1;
  len(p) = r + 1 - l;
  sum(p) = r + 1 - l;
  if (l == r) return;
  int mid = (l + r) >> 1;
  build(p << 1, l, mid);
  build(p << 1 | 1, mid + 1, r);
  // pushup(p);
}
void update(int L, int R, int d, int p, int l, int r) {
  if (L <= l && R >= r) {
    addtag(d, p);
    return;
  }
  pushdown(p);
  int mid = (l + r) >> 1;
  if (L <= mid) update(L, R, d, p << 1, l, mid);
  if (R > mid) update(L, R, d, p << 1 | 1, mid + 1, r);
  pushup(p);
}
Node query(int L, int R, int p, int l, int r) {
  if (L <= l && R >= r) return tr[p];
  pushdown(p);
  int mid = (l + r) >> 1;
  if (L <= mid && R > mid) {
    Node a = query(L, R, p << 1, l, mid);
    Node b = query(L, R, p << 1 | 1, mid + 1, r);
    Node c;
    merge(a, b, c);
    return c;
  }
  if (L <= mid)
    return query(L, R, p << 1, l, mid);
  else
    return query(L, R, p << 1 | 1, mid + 1, r);
}
void change(int l1, int r1, int l2, int r2) {
  int cnt1 = query(l1, r1, 1, 1, n).sum;
  if (!cnt1) return;
  update(l1, r1, 0, 1, 1, n);
  int cnt2 = r2 + 1 - l2 - query(l2, r2, 1, 1, n).sum;
  if (cnt1 >= cnt2)
    update(l2, r2, 1, 1, 1, n);
  else {
    int l = l2, r = r2;
    while (l <= r) {
      int mid = (l + r) >> 1;
      int cnt0 = mid + 1 - l2 - query(l2, mid, 1, 1, n).sum;  // 0 个数
      if (cnt1 >= cnt0)
        l = mid + 1;
      else
        r = mid - 1;
    }
    update(l2, r, 1, 1, 1, n);
  }
}
int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cin >> n >> m;
  build(1, 1, n);
  while (m--) {
    int op, l, r, x, y;
    cin >> op >> l >> r;
    if (op == 1) cin >> x >> y;
    if (op == 0) update(l, r, 0, 1, 1, n);
    if (op == 1) change(l, r, x, y);
    if (op == 2) cout << query(l, r, 1, 1, n).mx << endl;
  }
  return 0;
}